package com.lin.cloud.disk.service.impl;

import com.lin.cloud.disk.entity.pojo.UserDepartment;
import com.lin.cloud.disk.mapper.UserDepartmentMapper;
import com.lin.cloud.disk.service.IUserDepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * (UserDepartment)表服务实现类
 *
 * @author ljc
 * @since 2020-12-10 16:48:13
 */
@Service
@Slf4j
public class UserDepartmentServiceImpl implements IUserDepartmentService {

    @Resource
    private UserDepartmentMapper userDepartmentMapper;


    /**
     * 通过用户ID查询部门ID列表
     * @param userId
     * @return
     */
    @Override
    public List<Long> selectDepartmentIdListByUserId(Long userId) {
        if (null == userId || 0 == userId){
            return Collections.EMPTY_LIST;
        }
        return userDepartmentMapper.selectDepartmentIdListByUserId(userId);
    }

    @Override
    public void insert(UserDepartment userDepartment) {
        userDepartmentMapper.insert(userDepartment);
    }


    /**
     * 通过部门ID列表查询用户ID列表
     *
     * @param departmentIdList
     * @return
     */
    @Override
    public List<Long> selectUserIdListByDepartmentIdList(List<Long> departmentIdList) {
        if (CollectionUtils.isEmpty(departmentIdList)){
            return Collections.EMPTY_LIST;
        }
        return userDepartmentMapper.selectUserIdListByDepartmentIdList(departmentIdList);
    }

    /**
     * 批量插入用户部门关系
     * @param userDepartmentList
     */
    @Override
    public void batchInsertUserDepartment(List<UserDepartment> userDepartmentList){
        if (CollectionUtils.isNotEmpty(userDepartmentList)){
            userDepartmentMapper.batchInsertUserDepartment(userDepartmentList);
        }
    }

    /**
     * 批量删除用户部门关系
     * @param departmentId
     * @param unAllocationUserList
     */
    @Override
    public void batchRemoveUserDepartment(Long departmentId, List<Long> unAllocationUserList){
        if (CollectionUtils.isNotEmpty(unAllocationUserList)){
            userDepartmentMapper.batchRemoveUserDepartment(departmentId, unAllocationUserList);
        }
    }
}